package org.PropertyManageMentSystem.Manager;

import org.PropertyManageMentSystem.Data.MysqlConfig;
import org.PropertyManageMentSystem.Data.Scheduler;
import org.PropertyManageMentSystem.Data.Worker;

import java.sql.*;

public class SchedulerManager {
    private Connection conn;

    public SchedulerManager(MysqlConfig config){
        try {
            //加载驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        try {
            //创建连接
            conn = DriverManager.getConnection(config.getUrl(), config.getUser(), config.getPassword());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public Scheduler getSchedulerById(Long schedulerId) throws Exception {
        String sql="select * from scheduler where schedulerId=?";
        PreparedStatement pst=conn.prepareStatement(sql);
        pst.setLong(1, schedulerId);
        ResultSet rs = pst.executeQuery();
        rs.next();
        return new Scheduler(schedulerId, rs.getString("name"), rs.getString("tel")
                );
    }
}
